#ifndef __SCENE_OBJECT_H_INCLUDE__
#define __SCENE_OBJECT_H_INCLUDE__

#include "Component.h"
#include <vector>
#include "cocos2d.h"
using namespace cocos2d;
using namespace std;
class SceneObject
{
public:
	typedef vector<Component*> ComponentList;
	friend class SceneObjectManager;

public:
	SceneObject(const CCString& name, const CCString& layer);
	~SceneObject();

	const CCString& getName(){
		return m_name;
	}

	void setName(const CCString& str) {
		m_name=str;
	}

	Component* attachComponent(ComponentType type);

	void detachComponent(Component* component );

	int getComponentNum() const {
		return m_components.size();
	}

	Component* getComponent(int index) {
		CCAssert(!(index < getComponentNum()),"This is an error index");
		return m_components[index];
	}

	void getComponents(ComponentType type, ComponentList& components);

	Component* getComponentFromType(ComponentType type);

	void update(int deltaTimeMs);

	const CCString& getLayer() const {
		return m_layer;
	}

	void changeLayer(const CCString& layer);

protected:
	virtual Component* _createComponent(ComponentType type);
	virtual void _deleteComponent(Component* pCom);

	CCString m_layer;
	ComponentList m_components;
	CCString m_name;

	bool m_destroy;
};

#endif//__SCENE_OBJECT_H_INCLUDE__